//
//  UIButton + Extension.swift
//  Residual_mem
//
//  Created by 武振磊 on 16/7/19.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIButton{
    ///   遍历构造函数
    ///   - parameter imageName:     图片名称
    ///   - parameter backImageName: 背景图片名称
    ///   - returns: UIButton
    convenience init(imageName: String, backImageName: String){
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        sizeToFit()
    }
    ///   遍历构造函数
    ///   - parameter title:         title
    ///   - parameter color:         titleColor
    ///   - parameter backImageName: backImageName
    ///   - parameter fontSize:      fontSize
    ///   - returns: UIButton
    convenience init(title: String, color: UIColor, backImageName: String, fontSize: CGFloat){
        
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }

}
